<?php
/**
 * Created by PhpStorm.
 * User: kongqi
 * Date: 2019/11/30
 * Time: 20:40
 */

namespace App\Plugin\HostServer\Services;

use App\Plugin\HostServer\Front\Mail\EmailNotify;
use Illuminate\Support\Facades\Mail;

class NotifyService
{
    /**
     * 发送通知邮件站长
     * @param $title
     * @param $message，必须包含类型，区别不同视图
     * @throws \Exception
     */
    public static function orderNotifySiteUser($title, $message)
    {
        //接受
        $accept_email = config_cache_default('host_server.email_recipient');

        if (!empty($accept_email)) {
            $arr_email=explode('|',$accept_email);
            if(!empty($arr_email))
            {
                foreach ($arr_email as $k=>$v)
                {
                   
                    static::sendEmail($v, new EmailNotify($title, $message));
                }
            }

        }

    }
    public static function orderNotifyUser($email,$title, $message)
    {

        if (!empty($email)) {
            static::sendEmail($email, new EmailNotify($title, $message));
        }

    }

    public static function sendEmail($email, $model)
    {
        $email_send_type = config_cache_default('host_server.email_send_type', 2);
        if ($email_send_type == 2) {
            Mail::to($email)->send($model);
        } else {
            Mail::to($email)->queue($model->onQueue('email'));
            //需要监听队列发送
            //nohup php artisan queue:work redis --tries=3 --queue=email&
        }
    }

}